package com.sc.justification.component;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

import com.sc.justification.AppWindow;

public class ImageDialog extends JDialog {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ImageDialog dialog = new ImageDialog();
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the dialog.
	 */
	public ImageDialog() {
		
		setBounds(100, 100, 642, 544);
		setLocationRelativeTo(AppWindow.frame);
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		final JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.SOUTH);
		
		JButton btnNewButton = new JButton("导入");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFileChooser chooser=new JFileChooser();
				chooser.setApproveButtonText("确定");
				chooser.setDialogTitle("打开文件");
	            int result = chooser.showOpenDialog(AppWindow.frame);
	            if (result == JFileChooser.APPROVE_OPTION)
	            {
	                File file = chooser.getSelectedFile();
	                getContentPane().remove(panel);
	                try {
						getContentPane().add(new ImageShow(file.getPath()));
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
	            }


			}
		});
		panel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("导出到word");
		panel.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("退出");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(e.getSource());
			}
		});
		panel.add(btnNewButton_2);

	}

}
